#ifndef CC_PUB_H
#define CC_PUB_H

/*******    Public header file *****************/
#include "cc_type.h"

/*******    Define  ***************************/
#define CFG_LOOP_CALC			// 
#ifdef 	CFG_LOOP_CALC		
// S:START_INDEX  E:END_INDEX LoopSz:SZ
// Empty Num 
#define LOOP_CALC(VAL,S,E,SZ) do{\
	if((S) < (E)){\
		(VAL) = (E) - (S);\
	} else {\
		(VAL) = (SZ)-(S)+(E);\
	}\
}while(0);

// Recevice Num
#define LOOP_CALC_ZERO(VAL,S,E,SZ) do{\
	if((S) > (E)){\
		(VAL) = (SZ)-(S)+(E);\
	} else {\
		(VAL) = (E) - (S);\
	}\
}while(0);

#endif

#define CFG_MEM_API             //  内存操作模块
#ifdef 	CFG_MEM_API
extern void cc_memcpy(unsigned char* p2da,unsigned char * p2sa,unsigned int size);
extern int cc_memcmp(unsigned char* p2da,unsigned char * p2sa,unsigned int size); //true 1;fault 0
extern void cc_memset(unsigned char* p2da,unsigned char val,unsigned int size);
extern void cc_memcfb(unsigned char* p2da,unsigned char* p2sa,unsigned int size);

#define MEMCPY(DA,SA,LEN)    cc_memcpy(DA,SA,LEN)
#define MEMSET(DA,VAL,LEN)   cc_memset(DA,VAL,LEN)
#define MEMCMP(S1,S2,LEN)    cc_memcmp(S1,S2,LEN)
#define MEMCFB(DA,SA,LEN)    cc_memcfb(DA,SA,LEN)

#else // 标准API

#define MEMCPY(DA,SA,LEN)    memcpy(DA,SA,LEN)
#define MEMSET(DA,VAL,LEN)   memset(DA,VAL,LEN)
#define MEMCMP(S1,S2,LEN)    memcmp(S1,S2,LEN)
// #define MEMCFB(DA,SA,LEN)    cc_memcfb(DA,SA,LEN)
#endif

#define CFG_MSTICK_API			//	最基础的API
#ifdef CFG_MSTICK_API			
extern void MsTick_Init(tMs (*p2f_gettick)(void));
extern tMs GetNowTick(void);
extern int Check_TimeOut(tMs oldtick,tMs diff_tick); //rule : OutTime:RET_OT
#endif

#define CFG_TINY_DBG_LOG_API	// LOG 简单型接口
#ifdef 	CFG_TINY_DBG_LOG_API

// TODO: Set TLOG_PRINT API 	
// #define TLOG_PRINT 		LLOG 
// #define TLOG_PRINT 		printf 
// #define TLOG_PRINT(FMT,...) 

extern void TinyDbg_Log_Level(uint8_t Level,char* FuncName,uint16_t Line); 
#define LOG_ERR() 	TinyDbg_Log_Level(1,(char*)__FUNCTION__,__LINE__)
#define LOG_MARK() 	TinyDbg_Log_Level(2,(char*)__FUNCTION__,__LINE__)	
#define LOG_WARN() 	TinyDbg_Log_Level(3,(char*)__FUNCTION__,__LINE__)
#define LOG_TICK() 	TinyDbg_Log_Level(4,(char*)__FUNCTION__,__LINE__)

extern void Log_ShowArray(const uint8_t* pStr,uint16_t Len,uint8_t *pPkg);
extern void Log_ShowArrayByCol(const uint8_t* pStr,uint8_t ColNum,
	uint16_t ArraySz,uint8_t* pArray);

#endif

#define CFG_STATIC_BUF_ALLOCATE		// 静态 MEM空间分配,不释放空间
#ifdef 	CFG_STATIC_BUF_ALLOCATE		

#define CFG_SET_SBUF_SZ	 	1024*32

extern void StaticBuf_Show(void);
extern void* CC_StaticBuf_Allocate(uint16_t Sz,uint16_t Line);

#define SMalloc(SZ)  CC_StaticBuf_Allocate(SZ,__LINE__)		

#endif

#define CFG_RANDOM_API			// 对于测试比较有用
#ifdef 	CFG_RANDOM_API
extern int CC_Random(int seed,int range);
#endif

#define CFG_SW_PTASK_API		// 线程 
#ifdef 	CFG_SW_PTASK_API
#include "sw_scg.h"
#endif

//

#endif 



